
package com.j2eefast.produce.pms.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;


import com.j2eefast.framework.sys.entity.SysUserEntity;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import com.j2eefast.produce.pms.entity.PmsSampleOutputEntity;
import com.j2eefast.produce.pms.mapper.PmsSampleOutputMapper;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import java.sql.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>生产管理样品出入库管理</p>
 *
 * @author: summer
 * @date: 2021-05-27 16:47
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */
@Service
@Transactional(readOnly = true)
public class PmsSampleOutputService extends ServiceImpl<PmsSampleOutputMapper, PmsSampleOutputEntity> {

	@Resource
	protected PmsSampleOutputMapper pmsSampleOutputMapper;


	/**
	 * 页面展示查询翻页
	 */
	public PageUtil findPage(Map<String, Object> params) {
		String sampleCode = (String) params.get("sampleCode");
		String sampleType = (String) params.get("sampleType");
		String registerName = (String) params.get("registerName");
		String beginTime = (String) params.get("beginTime");
		String endTime = (String) params.get("endTime");
		String beginTime2 = (String) params.get("beginTime2");
		String endTime2 = (String) params.get("endTime2");
		String sampleCode2 = (String) params.get("sampleCode2");
		String sampleType2 = (String) params.get("sampleType2");
		Page<PmsSampleOutputEntity> page = pmsSampleOutputMapper.findPage(
				new Query<PmsSampleOutputEntity>(params).getPage(),
				StrUtil.nullToDefault(sampleCode,""),
				StrUtil.nullToDefault(sampleType,""),
				StrUtil.nullToDefault(registerName,""),
				StrUtil.nullToDefault(beginTime,""),
				StrUtil.nullToDefault(endTime,""),
				StrUtil.nullToDefault(beginTime2,""),
				StrUtil.nullToDefault(endTime2,""),
				StrUtil.nullToDefault(sampleCode2,""),
				StrUtil.nullToDefault(sampleType2,""),
				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}


	public List<PmsSampleOutputEntity> findList(Map<String, Object> params) {
		String sampleCode = (String) params.get("sampleCode");
		String sampleType = (String) params.get("sampleType");
		String registerName = (String) params.get("registerName");
		List<PmsSampleOutputEntity> page = pmsSampleOutputMapper.findList(
				new Query<PmsSampleOutputEntity>(params).getPage(),
				StrUtil.nullToDefault(sampleCode,""),
				StrUtil.nullToDefault(sampleType,""),
				StrUtil.nullToDefault(registerName,""),
				(String) params.get(Constant.SQL_FILTER));
		return page;
	}




	@Transactional(rollbackFor = Exception.class)
	public boolean deleteByIds(Long[] ids) {

		return pmsSampleOutputMapper.deleteByIds(ids);

	}
	@Transactional(rollbackFor = Exception.class)
	public boolean updateCheck(Long id) {
		Long userId= UserUtils.getUserInfo().getId();

		return pmsSampleOutputMapper.updateCheck(id ,userId);

	}
	public SysUserEntity getSysById(@Param("userId")Long userId){
		return pmsSampleOutputMapper.getSysById(userId);
	}



}
